package com.ihr360.payroll.model.dto.salary.plan.payslip;

import com.ihr360.commons.model.entity.NumberIdWithTimeAndCompanyId;
import com.ihr360.commons.model.type.PayrollMergeType;
import com.ihr360.payroll.model.dto.salary.plan.SalaryPlan;
import com.ihr360.payroll.model.dto.salary.plan.config.MergedPayslipConfig;
import lombok.Data;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import java.util.ArrayList;
import java.util.List;

/**
 * @author tomtao
 */
@Data
@Entity
public class PayrollMergeSetting extends NumberIdWithTimeAndCompanyId<Long> {
    private static final long serialVersionUID = 8439139621453232128L;

    /** 名称 */
    @Column(length = 50, nullable = false)
    private String name;

    @ManyToMany(fetch = FetchType.LAZY)
    private List<PayrollTag> tags = new ArrayList<>();

    @ManyToMany(fetch = FetchType.LAZY)
    private List<SalaryPlan> salaryPlans = new ArrayList<>();

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private PayrollMergeType mergeType = PayrollMergeType.ALL;

    @ManyToOne(fetch = FetchType.LAZY)
    private SalaryPlan baseSalaryPlan;

    @OneToMany(mappedBy = "setting", cascade = CascadeType.ALL, orphanRemoval = true)
    @OrderBy("indexno")
    private List<PayrollMergeField> fields = new ArrayList<>();

    @ManyToOne(fetch = FetchType.LAZY)
    private MergedPayslipConfig payslipConfig;

}
